/*Author: Nathan Judkins
 * 
 * This class handles the different conference objects as well as
 * handling login and creation of new conferences. It should be 
 * the first model object accessed upon start up.
 * 
 * */
package Model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import FileIO.FileManager;

public class ConferenceManager 
{
  /**
   * The list of all the users associated
   * with the program.
   */
	private Set<User> my_users;
	
	/**
	 * The current User logged in (will be empty until log in is called)
	 */
	private User my_current_user;
	
	/**
	 * Contains all the conference objects
	 */
	private List<Conference> my_conferences;
	
	public ConferenceManager()
	{
		my_users = FileManager.loadUsers();
		my_conferences = FileManager.loadConferences();
	}
	
	/**
	 * Compares the string input versus all 
	 * of the known users and returns whether or 
	 * not that user is in the system. If he/she
	 * is in the system, then that person is 
	 * set to be the current user. 
	 * 
	 * Assumptions made: the controller needs 
	 * a true/false value for a visual indication of 
	 * fail/success. You log in based only on the user 
	 * name and not the email.
	 * 
	 * @param the_input The user name of the client
	 * @return if this user name is within the system.
	 */
	public boolean login(final String the_input)
	{
	  boolean isUser = false;
	  
	  if (the_input != null) //Should never be null but put a check in anyways
	  {
  		for (User s : my_users)
  		{
  		  if (s.isUserName(the_input))
  		  {
  		    isUser = true;
  		    my_current_user = s; //Do we need a current user variable?
  		    break;
  		  }  
  		}
	  }
		
		return isUser;
	}
	
	/**
	 * Should be called after logged in, takes the
	 * current user value and creates a conference 
	 * object for him where he's the program chair.
	 * 
	 * Assumes that the User is already logged in
	 * 
	 * @param the_conference_name The user's name for the conference
	 */
	public void addConference(final String the_conference_name, final Date the_deadline)
	{
		Conference newConf = new Conference(the_conference_name, my_current_user, the_deadline);
		my_conferences.add(newConf);
	}
	
	/**
	 * Should only be called for recreating data previously entered
	 * 
	 * @param the_conference_name String of the name of the conference.
	 * @param the_program_chair The program chair of the conference.
	 * @param the_users A list of users associated with this conference.
	 */
	 public void addConference(final String the_conference_name,
	     final User the_program_chair,
       final List<User> the_users,
       final Date the_deadline)
	 {
	   Conference newConf = new Conference(the_conference_name, the_program_chair, the_users, the_deadline);
	   my_conferences.add(newConf);
	 }
	
	/**
	 * Should be used to populate the list of users for this
	 * program and/or for testing purposes.
	 * 
	 * @param the_new_user
	 */
	public void addUser(final User the_new_user)
	{
	  if (the_new_user != null)
	    my_users.add(the_new_user);
	}
	
	public User getCurrentUser()
	{
	  return my_current_user;
	}
	
	 /**
   * Should return a copy of the list of Users
   * to protect the data inside ConferenceManager
   * 
   * @return a copy of the list of all User objects
   */
	public Set<User> getUsers()
	{
	  Set<User> allUsers = new HashSet<User>(my_users);
	 
	  return allUsers;
	}
	
	/**
	 * Should return a copy of the list of Conferences
	 * to protect the data inside ConferenceManager
	 * 
	 * @return a copy of the list of all conferences
	 */
	public ArrayList<Conference> getConferences()
	{
	  ArrayList<Conference> allConferences = new ArrayList<Conference>(my_conferences);
	  Collections.copy(allConferences, my_conferences);
	  return allConferences;
	}
	
	public int getConference()
	{
		return 0;
	}
}
